/**
 * @file report.type.ts
 * @description Defines the types for the sales report API response.
 * @created 2024-07-29
 */

export enum GenerateStatus {
  SUCCESS = "SUCCESS",
  FAIL = "FAIL",
  IN_PROCESS = "IN_PROCESS",
  NEED_ANNOTATION = "NEED_ANNOTATION",
  UNKNOWN = "UNKNOWN"
}

export interface GenerateReportState {
  generateStatus: GenerateStatus;
  progress: number;
}

// #region Base API Response
export interface ReportApiResponse {
  defaultSalesMethodology: string;
  report: ReportData;
  real: string;
  complete: string;
  status: string;
}

export interface ReportData {
  conferenceId: string;
  createdTime: string;
  customer: boolean;
  id: string;
  label: string; // e.g., 能力评估测试（滴滴）
  salesAnalysisReports: SalesAnalysisReport[];
  salesCounsellingReports: SalesCounsellingReport[];
  salesRelated: boolean;
  salesSummaryReports: SalesSummaryReport[];
}
// #endregion

// #region Sales Summary Reports
export interface SalesSummaryReport {
  createdTime?: string;
  defaultSalesMethodology: string;
  dimensionType: "SUMMARY";
  id: string;
  name: string; // e.g., 会议纪要
  report?: string;
  systemId: number;
  systemPreset: boolean;
  topicId: string;
  tries: number;
}
// #endregion

// #region Sales Analysis Reports
interface SalesAnalysisReportBase {
  createdTime: string;
  defaultSalesMethodology: string;
  dimensionType: "ANALYSIS";
  id: string;
  name: string;
  source: string;
  systemId: number;
  systemPreset: boolean;
  topicId: string;
  tries: number;
}

// ## Report Type: SALES_ACHIEVEMENT_ANALYSIS
export interface VisitTargetAnalysis {
  评估结果: string;
  理由: string;
  next_step: string;
  achievement: string;
  risk: string;
  requirement: string;
}

export interface VisitTargetAnalysisReport extends SalesAnalysisReportBase {
  promptType: "SALES_ACHIEVEMENT_ANALYSIS";
  report: VisitTargetAnalysis;
}

// ## Report Type: CUSTOMER_ATTITUDE
interface FeedbackDetail {
  时间戳: string;
  原话: string;
  理由: string;
}

interface CustomerFeedback {
  姓名: string;
  积极反馈: FeedbackDetail[];
  消极反馈: FeedbackDetail[];
  contactId: string;
}

interface CustomerEmotionAssessment {
  整体情绪: string;
  理由: string;
  姓名: string;
  contactId: string;
}

interface OverallCustomerAttitude {
  整体情绪: string;
  理由: string;
}

export interface CustomerAttitude {
  客户反馈: CustomerFeedback[];
  客户情绪评估: CustomerEmotionAssessment[];
  客户侧整体态度: OverallCustomerAttitude;
}

export interface CustomerAttitudeReport extends SalesAnalysisReportBase {
  promptType: "CUSTOMER_ATTITUDE";
  report: CustomerAttitude;
}

// ## Report Type: COMPETITION_SITUATION
interface Competitor {
  companyName: string;
  commonName: string;
  alternativeName: string;
  id: string;
}

interface ContextAnalysis {
  客户原话: string;
  上下文: string;
  关注点: string;
}

interface CompetitorMentionAnalysis {
  时间戳: string;
  上下文分析: ContextAnalysis;
}

interface MainFocus {
  部署灵活性: string;
  系统独立性: string;
  数据安全性: string;
  功能完整性: string;
}

interface PotentialNeeds {
  独立解决方案: string;
  差异化能力: string;
  隐私保护: string;
  成本效益: string;
}

interface CustomerFocus {
  主要关注方面: MainFocus;
  潜在需求或痛点: PotentialNeeds;
}

interface CompetitorReport {
  竞品提及内容的详细分析: CompetitorMentionAnalysis[];
  客户关注点: CustomerFocus;
  应对策略建议: string[];
}

interface CompetitionInfo {
  count: number;
  competitor: Competitor;
  sentences: string[];
  competitorReport: CompetitorReport;
}

export interface CompetitionSituationReport extends SalesAnalysisReportBase {
  promptType: "COMPETITION_SITUATION";
  report: CompetitionInfo[];
}

// ## Report Type: TODO
export interface TodoReport extends SalesAnalysisReportBase {
  promptType: "TODO";
  report: Record<string, unknown>; // Empty object
}

// ## Report Type: RISK_ITEM
interface RiskSource {
  时间戳?: string;
  原话: string;
}

interface RiskItem {
  风险描述: string;
  风险等级: string;
  来源: RiskSource;
  风险识别原因: string;
  潜在影响: string;
  应对措施: string[];
}

export interface RiskAnalysis {
  风险项: RiskItem[];
}

export interface RiskAnalysisReport extends SalesAnalysisReportBase {
  promptType: "RISK_ITEM";
  report: RiskAnalysis;
}

// Union type for all sales analysis reports
export type SalesAnalysisReport =
  | VisitTargetAnalysisReport
  | CustomerAttitudeReport
  | CompetitionSituationReport
  | TodoReport
  | RiskAnalysisReport;
// #endregion

// #region Sales Counselling Reports
interface SalesCounsellingReportBase {
  createdTime?: string;
  defaultSalesMethodology: string;
  dimensionType: "COUNSELLING";
  id: string;
  name: string;
  systemId: number;
  systemPreset: boolean;
  topicId: string;
  tries: number;
  targetSettings?: number;
}

// ## Report Name: 能力评估
interface AbilityAssessmentResponse {
  evaluationDimension: string;
  overallEvaluation: string;
  improvementSuggestions: string[];
}

interface AbilityAssessmentContent {
  name: string;
  score: string;
  reasonAndEvidence: string;
}

interface AbilityAssessmentTask {
  task: string;
  content: AbilityAssessmentContent;
}

export interface AbilityAssessment {
  response: AbilityAssessmentResponse;
  tasks: AbilityAssessmentTask[];
}

export interface AbilityAssessmentReport extends SalesCounsellingReportBase {
  name: "能力评估";
  content: string; // JSON string of settings
  report: AbilityAssessment;
}

// ## Report Name: 任务达成
interface TaskCompletionResponse {
  evaluationDimension: string;
  overallEvaluation: string;
  improvementSuggestions: string[];
}

interface SubTask {
  subTaskName: string;
  status: "incomplete" | "complete";
  comment?: string;
}

interface EvaluationResults {
  taskName: string;
  subTasks: SubTask[];
  comment: string;
}

interface TaskCompletionContent {
  evaluationResults: EvaluationResults;
}

interface TaskCompletionTask {
  task: string;
  content: TaskCompletionContent;
}

export interface TaskCompletion {
  response: TaskCompletionResponse;
  tasks: TaskCompletionTask[];
}

export interface TaskCompletionReport extends SalesCounsellingReportBase {
  name: "任务达成";
  promptType: "任务达成";
  content: string; // JSON string of settings
  report: TaskCompletion;
}

// ## Report Name: Simple Numeric Reports
export interface NumericReport extends SalesCounsellingReportBase {
  name: "销售说话时长占比" | "销售说话速率" | "最长销售说辞";
  report: string;
}

// ## Report Name: 销售耐心值
export interface PatienceReport extends SalesCounsellingReportBase {
  name: "销售耐心值";
  report: null;
}

// Union type for all sales counselling reports
export type SalesCounsellingReport =
  | AbilityAssessmentReport
  | TaskCompletionReport
  | NumericReport
  | PatienceReport;
// #endregion
